import json
import requests
from lxml import etree
import threading

with open('result.json', 'r') as f:
    items = json.load(f)


def get_url(goods_code):
    return 'http://public.npt.changyou.com//details/16/'+ goods_code +'.html'


for item in items:
    goods_code = item['goodsCode']
    r = requests.get(url=get_url(goods_code))

    if r.status_code == 200:
        selector = etree.HTML(r.text)
        jsl = selector.xpath('//*[@class="m-intro-block"]/div/div[2]/div[2]/p[2]/span[2]')[0].text
        item['jsl'] = jsl
        print('fetched... ' + str(goods_code) + ', value:' + jsl)
    else:
        print(str(goods_code) + 'load error!' + str(r.status_code))
    # break

# with open('result1.json', 'w') as f:
#     json.dump(items, f, indent=4, ensure_ascii=False)
